import { SkillCareerMapPanel } from "./SkillCareerMapPanel";
import { SkillInfo } from "../../../model/SkillInfo";
import { ObjCreate } from "../../common/ObjCreate";
import { TilePanel } from "../../equipment/TilePanel";
import { SkillItemGrade } from "../SkillItemGrade";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { LadderBattlefieldUtil } from "../../ladderBattlefield/LadderBattlefieldUtil";
import { Cache } from "../../../cache/Cache";
type int = number;
//class SkillCareerMapGradePanel
    
    export  class SkillCareerMapGradePanel extends SkillCareerMapPanel
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */currentMaxLevel(): Boolean
        {
            var loc1=null;
            if (_clickIndex > 0) 
            {
                loc1 = this._listPanel.getItemAt((_clickIndex - 1)) as SkillInfo;
                if (loc1 && loc1.levelMax) 
                {
                    return true;
                }
            }
            return false;
        }

        protected /* override */ initUI(): void
        {
            _bgBmp = ObjCreate.createBg(0, 0, 253, 389, this);
            this._listPanel = new TilePanel();
            this._listPanel.verticalGap = 3;
            this._listPanel.horizontalGap = 6;
            this._listPanel.move(0, 0);
            this._listPanel.setSize(252, 385);
            this._listPanel.x = 7;
            this._listPanel.y = 7;
            this._listPanel.columnWidth = 117;
            this._listPanel.rowHeight = 45;
            this._listPanel.setStyle("cellRenderer", SkillItemGrade);
            this.addChild(this._listPanel);
            return;
        }

        public /* override */ initSkill(arg1: Array<any>): void
        {
            super.initSkill(arg1);
            this._listPanel.dataProvider = new DataProvider(arg1);
            initCallLater();
            return;
        }

        protected /* override */ refreshSkill(arg1: int, arg2: SkillInfo): void
        {
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return;
            }
            super.refreshSkill(arg1, arg2);
            this._listPanel.replaceItemAt(arg2, (arg1 - 1));
            this._listPanel.invalidateItemAt((arg1 - 1));
            return;
        }

        public /* override */ itemClick(arg1: int): void
        {
            super.itemClick(arg1);
            if (arg1 == _clickIndex) 
            {
                return;
            }
            _clickIndex = arg1;
            this._listPanel.selectedIndex = (arg1 - 1);
            return;
        }

        public /* override */ updateSkill(arg1: SkillInfo): SkillInfo
        {
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return null;
            }
            super.updateSkill(arg1);
            _lastUpdateInfo = arg1;
            arg1.levelUpAbleShow = false;
            arg1.levelUpAbleEffect = false;
            this._listPanel.replaceItemAt(arg1, (arg1.position - 1));
            this._listPanel.invalidateItemAt((arg1.position - 1));
            return this.guideLevelUp(Cache.instance.skill.skillLearnAble, true);
        }

        public /* override */ guideLevelUp(arg1: Array<any>, arg2: Boolean): SkillInfo
        {
            var loc1=0;
            var loc3=null;
            var loc4=false;
            var loc5=0;
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return null;
            }
            super.guideLevelUp(arg1, arg2);
            var loc2=arg1.length;
            while (loc1 < loc2) 
            {
                (loc3 = arg1[loc1]).levelUpAbleShow = true;
                if (!loc4) 
                {
                    loc4 = true;
                    if (arg2 || this.currentMaxLevel()) 
                    {
                        this.itemClick(loc3.position);
                        loc5 = loc3.position;
                    }
                    loc3.levelUpAbleEffect = true;
                }
                this._listPanel.replaceItemAt(loc3, (loc3.position - 1));
                this._listPanel.invalidateItemAt((loc3.position - 1));
                ++loc1;
            }
            if (loc5 != 0) 
            {
                return this._listPanel.getItemAt((loc5 - 1)) as SkillInfo;
            }
            return null;
        }

        public /* override */ guideLevelUpClear(): void
        {
            var loc1=0;
            var loc3=null;
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return;
            }
            super.guideLevelUpClear();
            var loc2=this._listPanel.dataProvider.length;
            while (loc1 < loc2) 
            {
                loc3 = this._listPanel.getItemAt(loc1) as SkillInfo;
                loc3.levelUpAbleShow = false;
                loc3.levelUpAbleEffect = false;
                this._listPanel.replaceItemAt(loc3, loc1);
                this._listPanel.invalidateItemAt((loc3.position - 1));
                ++loc1;
            }
            return;
        }

        protected /* var */_listPanel: TilePanel;
    }
